﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-26>
//创建作者：<郭登杰>
//功能说明：来函流程公共控件-审批详情 审批信息(计划变更)
//********************************************************************************//
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Controls.LAIHANLC
{
    public partial class UCLHLCXXXXSHENPIXX_JHBG : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 变量

        private SpHelper _sphelper = new SpHelper();

        #endregion 

        #region 属性

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        #endregion

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                this.InitControl();
            }
        }

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            this.txtJHL.ClientEnabled = false;
            this.txtSYL.ClientEnabled = false;
            this.txtSQL.ClientEnabled = false;
            this.txtYWY.ClientEnabled = false;
            this.txtZR.ClientEnabled = false;
            this.txtJSK.ClientEnabled = false;
            this.txtJCK.ClientEnabled = false;
            this.txtCZ.ClientEnabled = false;
        }

        /// <summary>
        /// 提交验证
        /// </summary>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            return rs;
        }

        /// <summary>
        /// 清除信息
        /// </summary>
        public void ClearInfo()
        {
            
        }

        /// <summary>
        /// 加载信息
        /// </summary>
        public void LoadInfo(Entity.YS_LH_LAIHANXX laihanxx)
        {
            DataRowCollection drc = new YS_JH_YONGHUYSSJProcess().SelectYS_JH_YONGHUYSSJsDynamic("I_JLZT=0 AND S_YONGHUH='" + laihanxx.S_YONGHUBH + "' AND I_Y=" + laihanxx.I_TZY + " AND I_M=" + laihanxx.I_TZM, null).Rows;
            if(drc.Count==0)
            {
                throw new Exception("找不到对应年月的用水数据");
            }
            this.txtJHL.Text = Convert.ToString(drc[0]["I_YUANJIHUA"]);
            this.txtSYL.Text = Convert.ToString(drc[0]["I_SHIYONGSL"]);
            /*
            int? syl_sy, yjh;
            DataSet ds = new SpHelper().P_YS_LH_YONGHUYSSJCX((int?)laihanxx.I_TZY, (int?)laihanxx.I_TZM, laihanxx.S_YONGHUBH, out yjh, out syl_sy);
            this.txtJHL.Text = yjh.ToString();
            this.txtSYL.Text = syl_sy.ToString();
            */
            /*
            //获取计划量,实用量
            DataRowCollection drc = new SpHelper().P_YS_LH_YONGHUYSSJCX((int?)laihanxx.I_TZY, (int?)laihanxx.I_TZM, laihanxx.S_YONGHUBH, out yjh, out syl_sy, null).Tables[0].Rows;
            for (int i = 0; i < drc.Count; i++)
            {
                //原计划
                if (drc[i]["I_Y"] == Convert.DBNull)
                {
                    this.txtJHL.Text=Convert.ToString(drc[i]["IM"+laihanxx.I_M]);
                }
                else //实用量
                {
                    this.txtSYL.Text = Convert.ToString(drc[i]["IM" + (laihanxx.I_M)]);
                }
            }*/
            //申请量至审批量
            drc = this._sphelper.P_YS_LHGETSHENPIYJS((int)this.LaiHanLX, laihanxx.S_LAIHANBH).Tables[0].Rows;
            List<int> indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int)laihanxx.I_LAIHANLX, eLaiHanLCBH.登记);
            this.txtSQL.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]) : "";
            this.txtJHL.Text = Convert.ToString(drc[indexes[0]]["I_YUANJIHUA"]);
            this.txtSYL.Text = Convert.ToString(drc[indexes[0]]["I_SHIYONGSL"]);
            indexes = LaiHanLCTools.GetNeedRowIndexs(drc,(int)laihanxx.I_LAIHANLX,eLaiHanLCBH.业务员);
            this.txtYWY.Text =indexes.Count>0? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]):"";
            indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int)laihanxx.I_LAIHANLX, eLaiHanLCBH.主任);
            this.txtZR.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]) : "";
            indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int)laihanxx.I_LAIHANLX, eLaiHanLCBH.节水科);
            this.txtJSK.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]) : "";
            indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int)laihanxx.I_LAIHANLX, eLaiHanLCBH.计财科);
            this.txtJCK.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]) : "";
            indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int)laihanxx.I_LAIHANLX, eLaiHanLCBH.处长);
            this.txtCZ.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["I_SHENPIL"]) : "";
        }
    }
}